using System;
using UnityEngine;

namespace MaterialUI
{
	public class AutoTweenVector3 : AutoTween
	{
		private Func<Vector3> m_GetStartValue;

		private Func<Vector3> m_GetTargetValue;

		private Action<Vector3> m_UpdateValue;

		private Vector3 m_StartValue;

		private Vector3 m_TargetValue;

		protected override float GetValue(bool isEnd, int valueIndex)
		{
			return (!isEnd) ? m_GetStartValue()[valueIndex] : m_GetTargetValue()[valueIndex];
		}

		protected override int ValueLength()
		{
			return 3;
		}

		public void Initialize(Action<Vector3> updateValue, Func<Vector3> startValue, Func<Vector3> targetValue, float duration, float delay, Tween.TweenType tweenType, Action callback, AnimationCurve animationCurve, bool scaledTime, int id)
		{
			m_GetStartValue = startValue;
			m_UpdateValue = updateValue;
			m_GetTargetValue = targetValue;
			Initialize(duration, delay, tweenType, callback, animationCurve, scaledTime, id);
		}

		protected override void StartTween()
		{
			if (m_UpdateValue == null)
			{
				EndTween(callback: false);
				return;
			}
			base.StartTween();
			try
			{
				m_StartValue = m_GetStartValue();
				m_TargetValue = m_GetTargetValue();
			}
			catch (Exception)
			{
				EndTween(callback: false);
			}
		}

		protected override void OnUpdateValue()
		{
			if (m_UpdateValue == null)
			{
				EndTween(callback: false);
				return;
			}
			Vector3 vector = default(Vector3);
			vector.x = Tween.Evaluate(m_TweenType, m_StartValue.x, m_TargetValue.x, m_DeltaTime, m_Duration, m_CustomCurve);
			vector.y = Tween.Evaluate(m_TweenType, m_StartValue.y, m_TargetValue.y, m_DeltaTime, m_Duration, m_CustomCurve);
			vector.z = Tween.Evaluate(m_TweenType, m_StartValue.z, m_TargetValue.z, m_DeltaTime, m_Duration, m_CustomCurve);
			Vector3 obj = vector;
			m_UpdateValue(obj);
		}

		protected override void OnFinalUpdateValue()
		{
			if (m_UpdateValue != null)
			{
				m_UpdateValue(m_TargetValue);
			}
		}
	}
}
